/*
 * XML.h
 *
 *  Created on: Jan 15, 2011
 *      Author: LyonsDesktop
 */

#ifndef XML_H_
#define XML_H_
#pragma once

#include <iostream>
#include <string>
#include <vector>

namespace XML
{
	//! An XML node in a XML tree.
	class Element
	{
	public:
		class Parameter
		{
		public:
			std::string Name;
			std::string Value;
		};

		Element* Parent;
		std::vector<Element*> Nodes;
		std::vector<Parameter> Parameters;

		Parameter* GetParameter(std::string Name);

		std::string Name;
		std::string Source;
		std::string Subtext;

		int StartPos;
		int EndPos;

		void WriteTo(std::ostream& o, int depth = 0);
		void WriteFileTo(std::ostream& o, int depth = 0);

		Element() { }
		Element(std::string& Name) : Name(Name) { }

		Element* GetElement(std::string Name, Element* cur = 0, bool recurse = false);
		~Element();
	};

	//! Represents an XML body.
	class Body
	{
	public:
		Element* root;

		//! Get the first node in the body with this name.
		Element* GetElement(std::string Name) { return (root) ? root->GetElement(Name, 0, true) : 0; }

		//! Load this body from the specified XML text.
		Body(std::string& Text);
		~Body();
	};
}


#endif /* XML_H_ */
